// pages/bodyteli/index.js
var moment = require('moment');

var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userId: '',
    value:'',
    arrda:[],
    timeSelet: 1,
        startTime: '',
        endTime: '',
        keyword:'',
        show: false,
        classShow: false,
        timeShow: false,
        currentDate: new Date().getTime(),
        minDate:'',
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`;
            }
            if (type === 'month') {
                return `${value}月`;
            }
            if (type === 'day') {
                return `${value}日`;
            }
            return value;
        },

        //体制情况
        tizhi:[],
        tuijiagood:[],
     

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.userId = wx.getStorageSync('userId')
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  showFiltrate(){
    this.setData({
      classShow: !this.data.classShow,
      timeShow: !this.data.timeShow,
  });
  },
  
  onChange(e){
    this.setData({
      value: e.detail,
    });
    wx.request({
      url: app.globalData.url + '/zkxj/body/resultList',
      data: {
        "userId": this.data.userId,
        "keyWord": e.detail,
        "currPage": 1,
        "pageSize": 190,
        "endTime": this.data.endTime,
	"startTime": this.data.startTime,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        console.log(res.data.data.list);
        this.setData({
          arrda:res.data.data.list
        })
      }
    })
console.log( e.detail);
  },
  finishTimeHanler(){
console.log(this.data.startTime,this.data.endTime);
if(this.data.startTime!=''&&this.data.endTime!=''){

  this.setData({
    timeShow: false,
  });
  wx.request({
    url: app.globalData.url + '/zkxj/body/resultList',
    data: {
      "userId": this.data.userId,
        "keyWord": this.data.value,
      "currPage": 1,
      "pageSize": 190,
      "endTime": this.data.endTime,
	"startTime": this.data.startTime,
    },
    method: 'POST',
    header: {
      'content-type': 'application/json',
      'token': wx.getStorageSync('token')
    },
    success: (res) => {
      console.log(res.data.data.list);
      this.setData({
        arrda:res.data.data.list
      })
    }
  })
}
  },
  handletopadd(){
    wx.navigateTo({
      url: '/pages/detectioninfo/index',
    })
  },
  getlist() {
    wx.request({
      url: app.globalData.url + '/zkxj/body/resultList',
      data: {
        "userId": this.data.userId,
        "currPage": 1,
      	"pageSize": 190,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        console.log(res.data.data.list);
        this.setData({
          arrda:res.data.data.list,
          tizhi:res.data.data.list[0].titleList,
          tuijiagood:res.data.data.list[0].recGoodList
        })
        // if(res.data.code==0){
        //   wx.showToast({
        //     title: '升级成功!',
        //     icon: 'success',
        //     duration: 1000,
        //     mask: true
        //   })

        // }else{
        //   wx.showToast({
        //     title: res.data.msg,
        //     icon: 'error',
        //     duration: 1000,
        //     mask: true
        //   })
        // }

      }
    })
  },
   //重置时间筛选
   resetTime(){ 
    this.setData({ 
        startTime:'',
        endTime:''
    })
 },
  //时间筛选
  showTimeFiltrate() {
    this.setData({
        timeShow: !this.data.timeShow,
        classShow: false,
    });
    if (this.data.timeShow) {
        this.setData({
            show: true
        })
    } else {
        this.setData({
            show: false
        })
    }
   
},
changeTimeSelect() {
    this.setData({
        timeSelet: 1
    })
},
changeTimeSelect2() {
    this.setData({
        timeSelet: 2
    })
},
onInput(event) {
    if (this.data.timeSelet === 1) {
        this.setData({
            startTime: moment(event.detail).format("YYYY-MM-DD"),
        });
    } else {
        this.setData({
            endTime: moment(event.detail).format("YYYY-MM-DD"),
        });
    }
    this.setData({
        currentDate: event.detail,
    });
},
  handletode(e){
    const goodid = e.currentTarget.dataset.inda
    wx.navigateTo({
      url: `/pages/result/index?detectionId=${goodid}` 
  })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})